import Vue from 'vue'
import Vuex from 'vuex'
import persist from "vuex-persist"
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    data:[]
  },
  mutations: {
    UpData(state,item){
      let flag = true;
      state.data.forEach(items=>{
        if(item._id == items._id){
          item.num++;
          flag = false;
        }
      })
      if(flag == true){
        state.data.push(item)
      }
      // console.log(state.data);
    },
    Delete(state,index){
      state.data.splice(index,1)
    }
  },
  actions: {
  },
  modules: {
  },
  plugins: [
    new persist({
        storage: window.localStorage,
    }).plugin,
],
})
